using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImmediateWindow
{
	public partial class ReferenceForm : Form
	{
		List<string> itsAvailableReferences;
		List<string> itsReferences;

		public ReferenceForm(List<string> refs,List<string> avail)
		{
			itsReferences = refs;
			itsAvailableReferences = avail;
			InitializeComponent();
		}

		private void ReferenceForm_Load(object sender, EventArgs e)
		{
			AvailableBindingSource.DataSource = itsAvailableReferences;
			AvailableDataControl.DataSource = AvailableBindingSource;
			RefsBindingSource.DataSource = itsReferences;
			RefsDataControl.DataSource = RefsBindingSource;
		}

		private void QuitButton_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void AddRefButton_Click(object sender, EventArgs e)
		{
			foreach(string refentry in AvailableDataControl.SelectedItems)
				itsReferences.Add(refentry);
			foreach(string refentry in AvailableDataControl.SelectedItems)
				itsAvailableReferences.Remove(refentry);
			AvailableBindingSource.CurrencyManager.Refresh();
			RefsBindingSource.CurrencyManager.Refresh();
		}

		private void DelRefButton_Click(object sender, EventArgs e)
		{
			foreach(string refentry in RefsDataControl.SelectedItems)
				itsAvailableReferences.Add(refentry);
			foreach(string refentry in RefsDataControl.SelectedItems)
				itsReferences.Remove(refentry);
			AvailableBindingSource.CurrencyManager.Refresh();
			RefsBindingSource.CurrencyManager.Refresh();
		}

		private void AddCustomRefButton_Click(object sender, EventArgs e)
		{
			if (TheOpenFileDialog.ShowDialog() != DialogResult.OK) return;
			itsAvailableReferences.Add(TheOpenFileDialog.FileName);
			AvailableBindingSource.CurrencyManager.Refresh();
      AvailableDataControl.SelectedIndices.Clear();
      AvailableDataControl.SelectedItem = TheOpenFileDialog.FileName;
		}
	}
}